#ifndef Algebra_MpiException_h
#define Algebra_MpiException_h

#include "AlgebraModule.h"
#include <cassert>
#include <exception>

SG_NAMESPACE_OPEN
namespace Algebra
{
    /**
     * @brief Exception raised while calling the MPI routines.
     *
     * @author nene
     * @date December, 2024.
     */
    class ALGEBRA_EXPORT MpiException : public std::exception
    {
    public:
        MpiException (const char* routine, int result_code);
        ~MpiException ();

        /** Return the string used to identify the exception. */
        virtual const char* what () const throw ()
        {
            return this->message.c_str ();
        }

    protected:
        /// The formatted error message
        std::string message;
    };

#define MPI_CHECK_RESULT(MPIFunc, Args)        \
    {                                          \
        int _check_result = MPIFunc Args;      \
        assert (_check_result == MPI_SUCCESS); \
    }
}

SG_NAMESPACE_CLOSE

#endif  //  Algebra_MpiException_h